home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2002 #12 / Amiga Plus CD - 2002 - No. 12.iso / AmigaOS / Aplus_Dev / AP-Website / download / pgp / pgp5gui-174b.lha / PGP5GUI-Src.lha / PGP5GUI-Src / PGP5Interface.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-23  |  19.7 KB  |  785 lines

  1. /*
  2. ** PGP5GUI - A GUI using Magic User Interface v3.8
  3. **
  4. ** Copyright 23-JUNE-1998 by Stefan Zakarias, All Rights Reserved.
  5. **
  6. ** This source code is released as FREEWARE - Use it for whatever you like,
  7. ** as long as NO financial reward is gained by you for such usage.
  8. **
  9. ** If you use any parts of the this source code for anything, give ME credit
  10. ** wherever credit is due, please ;-)
  11. */
  12.  
  13. /*
  14. ** Functions to handle the interface between the PGP5 programs and the GUI
  15. */
  16.  
  17. /* Library stuff */
  18. #include <libraries/asl.h>
  19. #include <libraries/mui.h>
  20. #include <dos/dostags.h>
  21. #include <exec/memory.h>
  22.  
  23. /* Prototypes */
  24. #ifdef __GNUC__
  25. #include <proto/alib.h>
  26. #endif
  27.  
  28. #include <proto/muimaster.h>
  29. #include <proto/exec.h>
  30. #include <clib/alib_protos.h>
  31. #include <clib/alib_stdio_protos.h>
  32. #include <proto/dos.h>
  33. #include <proto/asl.h>
  34.  
  35. /*  Ansi  */
  36. #include <string.h>
  37.  
  38. /* Include GUI stuff */
  39. #include "PGP5GUI.h"
  40.  
  41. #define EXEC_BUFF_SIZE ((256 * 16) + 320)
  42. #define TEMPFILE    "T:pgp5keys"
  43.  
  44. static ULONG systags[] =
  45. {
  46.        /* Make SYS_Input always the first tag.  It's altered later on! */
  47.     SYS_Input, 0,
  48.        SYS_Output, NULL,
  49.     TAG_DONE, TAG_DONE
  50. };
  51.  
  52. LONG EncClipMode, DecClipMode, SigClipMode, AddKeysClipMode;
  53. LONG prev_EncClipMode, prev_DecClipMode, prev_SigClipMode, prev_AddKeysClipMode;
  54.  
  55. /* Array of pointers to blocks of the 'keyselbuff' */
  56. char *keyselection[256];
  57. extern char *keystable[];
  58.  
  59. char *tempfile = TEMPFILE;
  60. char *PGP_path = "PGP:";
  61. char *PGP5Key_asc = "PGP5Key.asc";
  62.  
  63. char *warning_str = "WARNING...";
  64. char *OK_str = "OK";
  65.  
  66. /*
  67. ** Array to hold keys selected by the user.
  68. ** NOTE: The indices of 'keyselection[]' point to chunks of this array
  69. */
  70. char *keyselbuff = NULL;
  71.  
  72. /* Used for assembling multiple keyids to send to PGPx */
  73. char *keyidsbuff = NULL;
  74.  
  75. /* Array to hold the command line we send to DOS */
  76. char *exec_buff = NULL;
  77.  
  78. /* Memory to hold args. for encryption */
  79. char *enc_args_mem = NULL;
  80.  
  81. char *enc_mode;        /* Becomes: enc_args_mem */
  82. char *enc_options;    /* Becomes: enc_mode + 28 */
  83. char *enc_files;    /* Becomes: enc_options + 28 */
  84.  
  85. /* Memory to hold args. for decryption */
  86. char *dec_args_mem = NULL;
  87.  
  88. char *dec_outtype;    /* Becomes: dec_args_mem */
  89. char *dec_files;    /* Becomes: dec_outtype + 28 */
  90.  
  91. /* Memory to hold args. for signing */
  92. char *sig_args_mem = NULL;
  93.  
  94. char *sig_mode;        /* Becomes: sig_args_mem */
  95. char *sig_options;    /* Becomes: sig_mode + 28 */
  96. char *sig_files;    /* Becomes: sig_options + 28 */
  97.  
  98. /* Memory to hold file name for encryption from file */
  99. char *enc_name_mem = NULL;
  100.  
  101. char *encpath;        /* Becomes: enc_name_mem */
  102. char *encfile;        /* Becomes: encpath + 256 */
  103. char *encfilename;    /* Becomes: encfile + 256 */
  104.  
  105. /* Memory to hold file name for encryption from clip to file */
  106. char *encclip_name_mem = NULL;
  107.  
  108. char *encclippath;        /* Becomes: encclip_name_mem */
  109. char *encclipfile;        /* Becomes: encclippath + 256 */
  110. char *encclipfilename;    /* Becomes: encclipfile + 256 */
  111.  
  112. /* Memory to hold file name for decryption from file */
  113. char *dec_name_mem = NULL;
  114.  
  115. char *decpath;      /* Becomes: dec_name_mem */
  116. char *decfile;      /* Becomes: decpath + 256 */
  117. char *decfilename;  /* Becomes: decfile + 256 */
  118.  
  119. /* Memory to hold file name for decryption from clip to file */
  120. char *decclip_name_mem = NULL;
  121.  
  122. char *decclippath;        /* Becomes: decclip_name_mem */
  123. char *decclipfile;        /* Becomes: decclippath + 256 */
  124. char *decclipfilename;    /* Becomes: decclipfile + 256 */
  125.  
  126. /* Memory to hold file name for signing from file */
  127. char *sig_name_mem = NULL;
  128.  
  129. char *sigpath;      /* Becomes: sig_name_mem */
  130. char *sigfile;      /* Becomes: sigpath + 256 */
  131. char *sigfilename;  /* Becomes: sigfile + 256 */
  132.  
  133. /* Memory to hold file name for signing from clip to file */
  134. char *sigclip_name_mem = NULL;
  135.  
  136. char *sigclippath;        /* Becomes: sigclip_name_mem */
  137. char *sigclipfile;        /* Becomes: sigclippath + 256 */
  138. char *sigclipfilename;    /* Becomes: sigclipfile + 256 */
  139.  
  140. /* Memory to hold file name for Add Keys */
  141. char *addkeys_name_mem = NULL;
  142.  
  143. char *addkeyspath;      /* Becomes: addkeys_name_mem */
  144. char *addkeysfile;      /* Becomes: addkeyspath + 256 */
  145. char *addkeysfilename;  /* Becomes: addkeysfile + 256 */
  146.  
  147. /* Memory to hold file name for extracting key(s) to file */
  148. char *keys_extract_name_mem = NULL;
  149.  
  150. char *keys_extractpath;
  151. char *keys_extractfile;
  152. char *keys_extractfilename;
  153.  
  154. char *cwdscratch = NULL;
  155.  
  156. char *wincfgname = "ENVARC:PGP5GUI.wcfg";
  157. char *ReadyMSG = "\33cReady!";
  158.  
  159. extern BOOL listget;
  160.  
  161. /* Pointer to hold address of our console */
  162. BPTR console = NULL;
  163.  
  164. /* Array to hold the console specs. */
  165. UBYTE conspec[80];
  166.  
  167. struct Window *win = NULL;
  168. struct FileRequester *filerequester = NULL;
  169.  
  170. struct WinConfigs WinConfig =
  171. {
  172.     0,        /* con_LeftEdge */
  173.     20,        /* con_TopEdge */
  174.     640,    /* con_Width */
  175.     180,    /* con_Height */
  176.     0,            /* blank */
  177.     10,        /* asl_LeftEdge */
  178.     20,        /* asl_TopEdge */
  179.     310,    /* asl_Width */
  180.     180,    /* asl_Height */
  181.     0            /* end */
  182. };
  183.  
  184. extern ULONG frtags[];
  185.  
  186. extern int GenerateKeyStrings(char *filename);
  187. extern void StringToPathFile(char *fullpath, char *pathbuff, char *filebuff);
  188. extern void JoinNameParts(char *fullpath, char *pathbuff, char *filebuff);
  189.  
  190.  
  191. BOOL
  192. InitASLStuff(struct ObjApp *App)
  193. {
  194.     BOOL result = FALSE;
  195.     char *enctest, *dectest, *sigtest, *addkeystest;
  196.  
  197.     /* Initialise an ASL FileRequester structure with our values */
  198.     if (filerequester = (struct FileRequester *)
  199.                         AllocAslRequest(ASL_FileRequest, (struct TagItem *) frtags))
  200.     {
  201.         /* Get/Set the default paths for the various ASL Requesters */
  202.            get(App->STR_PA_Encrypt_FROMFILE,MUIA_String_Contents,&enctest);
  203.         StringToPathFile(enctest, encpath, encfile);
  204.  
  205.         get(App->STR_PA_Decrypt_TOFILE,MUIA_String_Contents,&dectest);
  206.         StringToPathFile(dectest, decpath, decfile);
  207.  
  208.         get(App->STR_PA_Sign_POPFILE,MUIA_String_Contents,&sigtest);
  209.         StringToPathFile(sigtest, sigpath, sigfile);
  210.  
  211.            get(App->STR_PA_Keys_ADD_KEYFILE,MUIA_String_Contents,&addkeystest);
  212.         StringToPathFile(addkeystest, addkeyspath, addkeysfile);
  213.  
  214.         /* Set the return code to 'no error' */
  215.         result = TRUE;
  216.     }
  217.  
  218.     /* Return the result of our operation */
  219.     return(result);
  220. }
  221.  
  222. void
  223. GetWinConfigs(void)
  224. {
  225.     int len, i, fnlen;
  226.     char linebuff[2088];            /* Buffer for config file */
  227.     char *bufptr;
  228.     BPTR filelock, filehandle;
  229.     char *WCfg;
  230.  
  231.     WCfg = (char *) &WinConfig;
  232.  
  233.     /* Quick-check to see if the file exists! */
  234.     filelock = Lock(wincfgname, ACCESS_READ);
  235.  
  236.     /* Did we get a lock on that file? */
  237.     if (filelock)
  238.     {
  239.         /* File was found...  We can (have to?) unlock it now */
  240.         UnLock(filelock);
  241.  
  242.         /* We have a record of previously saved window size data */
  243.         filehandle = Open(wincfgname, MODE_OLDFILE);
  244.  
  245.         /* Did DOS give us the O.K. to read it? */
  246.         if (filehandle)
  247.         {
  248.             /*
  249.             ** DOS says it's OK to use!
  250.             ** Read a string of up to 255 bytes from the record into 'linebuff'.
  251.             */
  252.             len = Read(filehandle, linebuff, 2600);
  253.  
  254.             Close(filehandle);
  255.  
  256.             /* Check length of record */
  257.             if (len >= sizeof(struct WinConfigs))
  258.             {
  259.                 /* Size of record is at least the size of WinConfigs... */
  260.                 for (i = 0; i < sizeof(struct WinConfigs); i++)
  261.                 {
  262.                     /* Copy linebuff to WinConfig structure (hope it's right ;-) */
  263.                     *(WCfg++) = linebuff[i];
  264.                 }
  265.  
  266.                 /* If size of record is bigger than size of WinConfigs... */
  267.                 if (len > sizeof(struct WinConfigs))
  268.                 {
  269.                     /*
  270.                     ** Getting to here should mean we have default file paths
  271.                     ** for the various ASL file requesters...
  272.                     */
  273.  
  274.                     /* Get position in the line buffer */
  275.                     bufptr = linebuff + sizeof(struct WinConfigs);
  276.  
  277.                     for(i = 0; i < 4; i++)
  278.                     {
  279.                         /* Get length of string at bufptr's starting position */
  280.                         fnlen = strlen(bufptr);
  281.  
  282.                         if (fnlen)
  283.                         {
  284.                             switch(i)
  285.                             {
  286.                                 case 0:
  287.                                     StringToPathFile(bufptr, encclippath, encclipfile);
  288.                                     break;
  289.  
  290.                                 case 1:
  291.                                     StringToPathFile(bufptr, decclippath, decclipfile);
  292.                                     break;
  293.  
  294.                                 case 2:
  295.                                     StringToPathFile(bufptr, sigclippath, sigclipfile);
  296.                                     break;
  297.  
  298.                                 case 3:
  299.                                     StringToPathFile(bufptr, keys_extractpath, keys_extractfile);
  300.                                     break;
  301.                             }
  302.                         }
  303.  
  304.                         bufptr += (fnlen + 1);
  305.                     }
  306.                 }
  307.             }
  308.         }
  309.     }
  310. }
  311.  
  312. /*
  313. ** Open a console window we can use for stdin/stdout
  314. */
  315. BOOL
  316. OpenConWin(struct ObjApp *App)
  317. {
  318.     struct Screen *screen;
  319.  
  320.     get(App->WI_Main, MUIA_Window_Screen, &screen);
  321.  
  322.     if (win = OpenWindowTags(NULL,
  323.             WA_Left, WinConfig.con_LeftEdge,
  324.             WA_Top, WinConfig.con_TopEdge,
  325.             WA_Width, WinConfig.con_Width,
  326.             WA_Height, WinConfig.con_Height,
  327.             WA_Flags, WFLG_SIZEGADGET | WFLG_DRAGBAR | WFLG_DEPTHGADGET |
  328.                       WFLG_SMART_REFRESH | WFLG_ACTIVATE | WFLG_RMBTRAP |
  329.                       WFLG_NOCAREREFRESH,
  330.             WA_Title, "AmigaPGP5 Output Window...",
  331.             WA_MinWidth, 319,
  332.             WA_MinHeight, 39,
  333.             WA_MaxWidth, -1,
  334.             WA_MaxHeight, -1,
  335.             WA_PubScreen, (ULONG) screen,
  336.             TAG_DONE))
  337.     {
  338.         /* Create console spec. and add pointer to window */
  339.         sprintf(conspec,"CON://///WINDOW0x%lx", win);
  340.  
  341.         if (console = Open(conspec, MODE_OLDFILE))
  342.         {
  343.             /* Set the 'SYS_Input' file tag */
  344.             systags[1] = (ULONG) console;
  345.  
  346.             /* Return flag: No Error */
  347.             return (TRUE);
  348.         }
  349.     }
  350.  
  351.     /* Error: Console or Window failed to open */
  352.     return (FALSE);
  353. }
  354.  
  355. void
  356. ShutDownConsole(void)
  357. {
  358.     BPTR filehandle;
  359.  
  360.     WinConfig.con_LeftEdge = win->LeftEdge;
  361.     WinConfig.con_TopEdge = win->TopEdge;
  362.     WinConfig.con_Width = win->Width;
  363.     WinConfig.con_Height = win->Height;
  364.  
  365.     WinConfig.blank = 0;
  366.  
  367.     WinConfig.asl_LeftEdge = frtags[13];
  368.     WinConfig.asl_TopEdge = frtags[15];
  369.     WinConfig.asl_Width = frtags[11];
  370.     WinConfig.asl_Height = frtags[9];
  371.  
  372.     WinConfig.end = 0;
  373.  
  374.     /* Open the 'ENVARC:PGP5GUI.wcfg' file */
  375.     filehandle = Open(wincfgname, MODE_READWRITE);
  376.  
  377.     /* Did DOS give us the O.K. to read it? */
  378.        if (filehandle)
  379.        {
  380.         /*
  381.         ** DOS says it's OK to use!
  382.         ** Write a string of size 'struct Winconfigs' bytes from WinConfig.
  383.         ** Disregard any errors...  It isn't that important that this file
  384.         ** is written to ;-)
  385.         */
  386.         Write(filehandle, &WinConfig, sizeof(struct WinConfigs));
  387.  
  388.         /* Write out the name of the last file we used for encrypt clip to file */
  389.         JoinNameParts(encclipfilename, encclippath, encclipfile);
  390.         Write(filehandle, encclipfilename, strlen(encclipfilename)+1);
  391.  
  392.         /* Write out the name of the last file we used for decrypt clip to file */
  393.         JoinNameParts(decclipfilename, decclippath, decclipfile);
  394.         Write(filehandle, decclipfilename, strlen(decclipfilename)+1);
  395.  
  396.         /* Write out the name of the last file we used for signing clip to file */
  397.         JoinNameParts(sigclipfilename, sigclippath, sigclipfile);
  398.         Write(filehandle, sigclipfilename, strlen(sigclipfilename)+1);
  399.  
  400.         /* Write out the name of the last file we used for extracting key to file */
  401.         JoinNameParts(keys_extractfilename, keys_extractpath, keys_extractfile);
  402.         Write(filehandle, keys_extractfilename, strlen(keys_extractfilename)+1);
  403.  
  404.         /* Finished with the file */
  405.         Close(filehandle);
  406.     }
  407.  
  408.     /* Close the console and it's window */
  409.     Close(console);
  410. }
  411.  
  412. /*
  413. ** Synchronous external command started with its own 'con:' Input/Output.
  414. ** Result will ONLY reflect whether System() call itself failed.
  415. ** If System() call fails, result will be -1L
  416. */
  417. void
  418. PGP5_Execute( UBYTE *command, struct ObjApp *App )
  419. {
  420.     /* Make the parent window go to sleep */
  421.     set(App->WI_Main,MUIA_Window_Sleep,TRUE);
  422.  
  423.     if (!listget)
  424.     {
  425.         set(App->TX_Status, MUIA_Text_Contents, "\33cProcessing...");
  426.     }
  427.     else
  428.     {
  429.         set(App->TX_Status, MUIA_Text_Contents, "\33cGetting key list...");
  430.     }
  431.  
  432.     /* Make the console window 'active' */
  433.     ActivateWindow(win);
  434.  
  435.     if (System(command, (struct TagItem *) systags))
  436.     {
  437.         MUI_Request(App->App, App->WI_Main, 0, warning_str, OK_str,
  438.                     "DOS command failed:\n%s", command);
  439.     }
  440.  
  441.     if (!listget)
  442.     {
  443.         /* Wake up the parent window */
  444.         set(App->WI_Main,MUIA_Window_Sleep,FALSE);
  445.  
  446.         /* Activate the parent window */
  447.         set(App->WI_Main,MUIA_Window_Activate,TRUE);
  448.  
  449.         set(App->TX_Status, MUIA_Text_Contents, ReadyMSG);
  450.     }
  451. }
  452.  
  453. int
  454. init_resources(void)
  455. {
  456.     int i;
  457.  
  458.     keyselbuff = AllocVec(256 * 16, MEMF_PUBLIC | MEMF_CLEAR);
  459.     keyidsbuff = AllocVec(EXEC_BUFF_SIZE, MEMF_PUBLIC | MEMF_CLEAR);
  460.  
  461.     exec_buff = AllocVec(EXEC_BUFF_SIZE, MEMF_PUBLIC | MEMF_CLEAR);
  462.  
  463.     enc_args_mem = AllocVec(28+28+512, MEMF_PUBLIC | MEMF_CLEAR);
  464.     enc_name_mem = AllocVec(256+256+512, MEMF_PUBLIC | MEMF_CLEAR);
  465.     encclip_name_mem = AllocVec(256+256+528, MEMF_PUBLIC | MEMF_CLEAR);
  466.  
  467.     dec_args_mem = AllocVec(28+512, MEMF_PUBLIC | MEMF_CLEAR);
  468.     dec_name_mem = AllocVec(256+256+512, MEMF_PUBLIC | MEMF_CLEAR);
  469.     decclip_name_mem = AllocVec(256+256+528, MEMF_PUBLIC | MEMF_CLEAR);
  470.  
  471.     sig_args_mem = AllocVec(28+28+512, MEMF_PUBLIC | MEMF_CLEAR);
  472.     sig_name_mem = AllocVec(256+256+512, MEMF_PUBLIC | MEMF_CLEAR);
  473.     sigclip_name_mem = AllocVec(256+256+528, MEMF_PUBLIC | MEMF_CLEAR);
  474.  
  475.     keys_extract_name_mem = AllocVec(256+256+512, MEMF_PUBLIC | MEMF_CLEAR);
  476.  
  477.     addkeys_name_mem = AllocVec(256+256+512, MEMF_PUBLIC | MEMF_CLEAR);
  478.  
  479.     cwdscratch = AllocVec(512, MEMF_PUBLIC | MEMF_CLEAR);
  480.  
  481.     /* Make sure we got ALL our memory we requested */
  482.     if (keyselbuff && keyidsbuff && exec_buff &&
  483.         enc_args_mem && enc_name_mem && encclip_name_mem &&
  484.         dec_args_mem && dec_name_mem && decclip_name_mem &&
  485.         sig_args_mem && sig_name_mem && sigclip_name_mem &&
  486.         keys_extract_name_mem && addkeys_name_mem && cwdscratch)
  487.     {
  488.         enc_mode = enc_args_mem;
  489.         enc_options = enc_mode + 28;
  490.         enc_files = enc_options + 28;
  491.  
  492.         encpath = enc_name_mem;
  493.         encfile = encpath + 256;
  494.         encfilename = encfile + 256;
  495.  
  496.         encclippath = encclip_name_mem;
  497.  
  498.         strcpy(encclippath, PGP_path);
  499.         encclipfile = encclippath + 256;
  500.         encclipfilename = encclipfile + 256;
  501.  
  502.         dec_outtype = dec_args_mem;
  503.         dec_files = dec_outtype + 28;
  504.  
  505.         decpath = dec_name_mem;
  506.         decfile = decpath + 256;
  507.         decfilename = decfile + 256;
  508.  
  509.         decclippath = decclip_name_mem;
  510.  
  511.         strcpy(decclippath, PGP_path);
  512.         decclipfile = decclippath + 256;
  513.         decclipfilename = decclipfile + 256;
  514.  
  515.         sig_mode = sig_args_mem;
  516.         sig_options = sig_mode + 28;
  517.         sig_files = sig_options + 28;
  518.  
  519.         sigpath = sig_name_mem;
  520.         sigfile = sigpath + 256;
  521.         sigfilename = sigfile + 256;
  522.  
  523.         sigclippath = sigclip_name_mem;
  524.  
  525.         strcpy(sigclippath, PGP_path);
  526.         sigclipfile = sigclippath + 256;
  527.         sigclipfilename = sigclipfile + 256;
  528.  
  529.         addkeyspath = addkeys_name_mem;
  530.         addkeysfile = addkeyspath + 256;
  531.         addkeysfilename = addkeysfile + 256;
  532.  
  533.         keys_extractpath = keys_extract_name_mem;
  534.  
  535.         strcpy(keys_extractpath, PGP_path);
  536.         keys_extractfile = keys_extractpath + 256;
  537.         strcpy(keys_extractfile, PGP5Key_asc);
  538.         keys_extractfilename = keys_extractfile + 256;
  539.  
  540.         /* Set the pointers to the chunks in our allocated memory */
  541.         for(i = 0; i < 256; i++)
  542.             keyselection[i] = keyselbuff + (i * 16);
  543.  
  544.         /* Init 'keystable[]' array */
  545.         for (i = 0; i < 1024; i++)
  546.             keystable[i] = 0;
  547.  
  548.         return(0);
  549.     }
  550.  
  551.     /* O-Oh... Missed out on an allocation somewhere */
  552.     return(RETURN_FAIL);
  553. }
  554.  
  555. void
  556. free_resources(void)
  557. {
  558.     int i;
  559.  
  560.     BPTR lock = Lock(tempfile, ACCESS_READ);
  561.  
  562.     if (lock)
  563.     {
  564.         UnLock(lock);
  565.         DeleteFile(tempfile);
  566.     }
  567.  
  568.     /* Free up any previously initialised 'keystable[]' memory */
  569.     for (i = 0; i < 1024; i++)
  570.     {
  571.         if (keystable[i])
  572.         {
  573.             FreeVec(keystable[i]);
  574.             keystable[i] = 0;
  575.         }
  576.     }
  577.  
  578.     if (cwdscratch)
  579.         FreeVec(cwdscratch);
  580.  
  581.     if (filerequester)
  582.         FreeAslRequest(filerequester);
  583.  
  584.     /* Save the window configs, close the console AND window */
  585.     if (console)
  586.         ShutDownConsole();
  587.  
  588.     if (addkeys_name_mem)
  589.         FreeVec(addkeys_name_mem);
  590.  
  591.     if (keys_extractpath)
  592.         FreeVec(keys_extractpath);
  593.  
  594.     if (sigclip_name_mem)
  595.         FreeVec(sigclip_name_mem);
  596.  
  597.     if (sig_name_mem)
  598.         FreeVec(sig_name_mem);
  599.  
  600.     if (sig_args_mem)
  601.         FreeVec(sig_args_mem);
  602.  
  603.     if (decclip_name_mem)
  604.         FreeVec(decclip_name_mem);
  605.  
  606.     if (dec_name_mem)
  607.         FreeVec(dec_name_mem);
  608.  
  609.     if (dec_args_mem)
  610.         FreeVec(dec_args_mem);
  611.  
  612.     if (encclip_name_mem)
  613.         FreeVec(encclip_name_mem);
  614.  
  615.     if (enc_name_mem)
  616.         FreeVec(enc_name_mem);
  617.  
  618.     if (enc_args_mem)
  619.         FreeVec(enc_args_mem);
  620.  
  621.     if (exec_buff)
  622.         FreeVec(exec_buff);
  623.  
  624.     if (keyidsbuff)
  625.         FreeVec(keyidsbuff);
  626.  
  627.     if (keyselbuff)
  628.         FreeVec(keyselbuff);
  629. }
  630.  
  631. /*
  632. ** Gets the value (selection) of a Cycle Gadget.
  633. ** Returns:  0 to (numentries - 1)
  634. */
  635. LONG
  636. GetCycle(Object *obj)
  637. {
  638.     LONG x;
  639.  
  640.     get(obj, MUIA_Cycle_Active, &x);
  641.     return(x);
  642. }
  643.  
  644. void
  645. EncFileOrClip(struct ObjApp *App)
  646. {
  647.     /* What mode did we switch to? */
  648.     EncClipMode = GetCycle(App->CY_Encrypt_CLIP);
  649.  
  650.     /* Did we change the setting?  'Coz we only want to toggle when necessary! */
  651.     if (EncClipMode != prev_EncClipMode)
  652.     {
  653.         /* Reset flag */
  654.         prev_EncClipMode = EncClipMode;
  655.  
  656.         if (EncClipMode < 2)
  657.         {
  658.             if (!EncClipMode)
  659.             {
  660.                 /* Encrypt from a file to file - Turn on everything */
  661.                 DoMethod(App->CY_Encrypt_CLIP, MUIM_MultiSet, MUIA_Disabled, FALSE,
  662.                         App->GR_Enc_File,
  663.                         App->CY_Encrypt_USEARMOR, App->CY_Encrypt_TEXTMODE,
  664.                         NULL);
  665.             }
  666.             else
  667.             {
  668.                 /* Encrypt from file to clipboard - Turn on file name group    */
  669.                 set(App->GR_Enc_File, MUIA_Disabled, FALSE);
  670.  
  671.                 /* Disable USEARMOR and TEXTMODE */
  672.                 DoMethod(App->CY_Encrypt_CLIP, MUIM_MultiSet, MUIA_Disabled, TRUE,
  673.                         App->CY_Encrypt_USEARMOR, App->CY_Encrypt_TEXTMODE,
  674.                         NULL);
  675.             }
  676.         }
  677.         else
  678.         {
  679.             /*
  680.             ** Encrypt from clipboard to file, or clipboard to clipboard...
  681.             ** Turn off everything
  682.             */
  683.             DoMethod(App->CY_Encrypt_CLIP, MUIM_MultiSet, MUIA_Disabled, TRUE,
  684.                     App->GR_Enc_File,
  685.                     App->CY_Encrypt_USEARMOR, App->CY_Encrypt_TEXTMODE,
  686.                     NULL);
  687.         }
  688.     }
  689. }
  690.  
  691. void
  692. DecFileOrClip(struct ObjApp *App)
  693. {
  694.     /* What mode did we switch to? */
  695.     DecClipMode = GetCycle(App->CY_Decrypt_OUTTYPE);
  696.  
  697.     /* Did we change the setting?  'Coz we only want to toggle when necessary! */
  698.     if (DecClipMode != prev_DecClipMode)
  699.     {
  700.         /* Reset flag */
  701.         prev_DecClipMode = DecClipMode;
  702.  
  703.         if (DecClipMode < 3)
  704.         {
  705.             /* Output from file to file, pager, or clip - Turn on file name group */
  706.             set(App->GR_Dec_File, MUIA_Disabled, FALSE);
  707.         }
  708.         else
  709.         {
  710.             /* From clipboard - Turn off file name group */
  711.             set(App->GR_Dec_File, MUIA_Disabled, TRUE);
  712.         }
  713.     }
  714. }
  715.  
  716. void
  717. SigFileOrClip(struct ObjApp *App)
  718. {
  719.     /* What mode did we switch to? */
  720.     SigClipMode = GetCycle(App->CY_Sign_CLIP);
  721.  
  722.     /* Did we change the setting?  'Coz we only want to toggle when necessary! */
  723.     if (SigClipMode != prev_SigClipMode)
  724.     {
  725.         /* Reset flag */
  726.         prev_SigClipMode = SigClipMode;
  727.  
  728.         if (SigClipMode < 2)
  729.         {
  730.             if (!SigClipMode)
  731.             {
  732.                 /* Sign from a file to file - Turn on everything */
  733.                 DoMethod(App->CY_Sign_CLIP, MUIM_MultiSet, MUIA_Disabled, FALSE,
  734.                         App->GR_Sig_File, App->CY_Sign_DETACH, App->CY_Sign_MODE,
  735.                         App->CY_Sign_TEXTMODE, NULL);
  736.             }
  737.             else
  738.             {
  739.                 /* Sign from file to clipboard - Turn on file name group */
  740.                 set(App->GR_Sig_File, MUIA_Disabled, FALSE);
  741.  
  742.                 /* Disable DETACH, ARMOR, TEXTMODE */
  743.                 DoMethod(App->CY_Sign_CLIP, MUIM_MultiSet, MUIA_Disabled, TRUE,
  744.                         App->CY_Sign_DETACH, App->CY_Sign_MODE,    App->CY_Sign_TEXTMODE,
  745.                         NULL);
  746.             }
  747.         }
  748.         else
  749.         {
  750.                 /*
  751.                 ** Sign from clipboard to file, or clipboard to clipboard...
  752.                 ** Turn off everything
  753.                 */
  754.                 DoMethod(App->CY_Sign_CLIP, MUIM_MultiSet, MUIA_Disabled, TRUE,
  755.                         App->GR_Sig_File, App->CY_Sign_DETACH, App->CY_Sign_MODE,
  756.                         App->CY_Sign_TEXTMODE, NULL);
  757.         }
  758.     }
  759. }
  760.  
  761. void
  762. AddKeysFileOrClip(struct ObjApp *App)
  763. {
  764.     /* What mode did we switch to? */
  765.     AddKeysClipMode = GetCycle(App->CY_KeysAdd_CLIP);
  766.  
  767.     /* Did we change the setting?  'Coz we only want to toggle when necessary! */
  768.     if (AddKeysClipMode != prev_AddKeysClipMode)
  769.     {
  770.         /* Reset flag */
  771.         prev_AddKeysClipMode = AddKeysClipMode;
  772.  
  773.         if (!AddKeysClipMode)
  774.         {
  775.             /* Add keys from file - Turn on file name group */
  776.             set(App->GR_Keys_AddFile, MUIA_Disabled, FALSE);
  777.         }
  778.         else
  779.         {
  780.             /* Add keys from clipboard - Turn off file name group */
  781.             set(App->GR_Keys_AddFile, MUIA_Disabled, TRUE);
  782.         }
  783.     }
  784. }
  785.